package com.yuanqi.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.yuanqi.common.Result;
import com.yuanqi.pojo.Product;
import com.yuanqi.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品分类设置接口
 */
@RestController
@RequestMapping("/api/product-category")
@RequiredArgsConstructor
public class ProductCategoryController {

    private final ProductService productService; // 注入服务

    @PostMapping("/set")
    public Result<Boolean> setCategory(@RequestParam Long productId, @RequestParam Long categoryId) {
        UpdateWrapper<Product> uw = new UpdateWrapper<>();
        uw.eq("id", productId).set("category_id", categoryId); // 更新分类
        boolean ok = productService.update(uw);
        return Result.success(ok);
    }
}


